package gao.xiaolei.util;

import java.lang.reflect.Field;

public class FieldUtil {

    public static <T> void setFieldsNull(String classPath, T object, String[] fields) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
        Class clazz = Class.forName(classPath);
        for (int i = 0, length = fields.length; i < length; i++) {
            Field field = clazz.getDeclaredField(fields[i]);
            //我们这里是操作私有属性，所以是用setAccessible方法跳过私有检测
            field.setAccessible(true);
            field.set(object, null);
        }
    }
}
